<?php 
	class yDiscuz{
	    var $initated = false ;
		var $object = null;
		var $db = null;
		var $config = null;
		static function &instance(){
			static $object = null;
			if(empty($object)){
				$object = new yDiscuz();	
			}
			return $object;
		}

		/**
			construct
		*/
		function yDiscuz(){
		    $this->_init_env();
		    $this->_init_conf();



		}
		function _init_env(){
            error_reporting(E_ERROR);
            if(phpversion()<'5.3.0'){

            }
            if(strtoupper(substr(PHP_OS,0,3) === 'WIN')){
                define(PHP_SLASH,"\\");
            }else{
                define(PHP_SLASH,"/");
            }




            $str = dirname(__FILE__);
            var_dump($str);
            $pos =  strrpos($str,PHP_SLASH,0);   // start from the 0
            $str = substr(dirname(__FILE__),0,$pos);
            define('DISCUZ_ROOT',$str);
            define('TIMESTAMP',time());
            var_dump(DISCUZ_ROOT);
            var_dump($str);




        }
            function timezone_set($timeoffset = 0){
                if(function_exists('date_default_timezone_set')) {
                        @date_default_timezone_set('Etc/GMT'.($timeoffset > 0 ? '-' : '+').(abs($timeoffset)));

		}

            }
            function _init_misc(){

                var_dump('_init_misc');

            }
        /**
         * initialize the config
         *
         *
         *
         *
         */
        private function _init_conf(){

            global $_config;
            //var_dump($_config);
            $_config  = null;
            if(!$_config){
                $this->error_log('config is missing!');
            }

        }
        /*
         *
         * */
        function init(){
            //var_dump($_config);
		    if(!$this->initated){
		        $this->_init_db();
            }
		    $this->initated = true;
        }


        /**
            初始化数据
         */
        private function _init_db(){
            if(!$this->db){
                $this->db = new db_mysql($this->config);
                $this->db->db_connect();
            }


        }

        /*
         *
         * */

        public function error_log($msg){
            $time = date("Y-m-d H:i:s",TIMESTAMP);
            $file = DISCUZ_ROOT.'/data/log/error_'.date("Y-m").'.php';
            echo __LINE__;
            $msg = "<?php exit; ?>\t{$time}:\t".str_replace(array("\t","\r","\n")," ")."\n";
            error_log($msg,3,$file);
        }

        function _debug(){
            var_dump($this);
        }
	}
?>